package cn.jeefast.rest.controller;

import cn.jeefast.common.utils.R;
import cn.jeefast.rest.entity.TbUser;
import cn.jeefast.rest.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.RegEx;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author theodo
 * @since 2020-01-02
 */
@RestController
@RequestMapping("/api")
public class TbUserController {

    @Autowired
    private TbUserService userService;

    /**
     * 更新用户信息
     * @param user
     * @return
     */
    @RequestMapping("/user/update")
    public R updateUser(TbUser user, HttpServletRequest request){
        Long userId = (Long) request.getAttribute("userId");
        if(userId.longValue()!=user.getUserId().longValue()){
            return R.error("未授权");
        }
        userService.updateById(user);
        return R.ok("更新成功").put("data",null);
    }
}
